package com.krtech.wecard.module.ramble.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.krtech.wecard.framework.utils.LoginUtil;
import com.krtech.wecard.module.ramble.entity.RambleDrawChance;
import com.krtech.wecard.module.ramble.entity.RambleLoginLog;
import com.krtech.wecard.module.ramble.service.RambleDrawChanceService;
import com.krtech.wecard.module.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rambleDrawChance")
@Slf4j
@Api(tags = "佳得乐漫步-抽奖机会")
public class RambleDrawChanceController {

    @Autowired
    private RambleDrawChanceService chanceService;

    @GetMapping("/page")
    @ApiOperation(value = "page")
    public Page<RambleDrawChance> page(Page<RambleDrawChance> page, String keyword) {
        QueryWrapper<RambleDrawChance> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(keyword)){
            wrapper.like(RambleDrawChance.COL_PHONE,keyword);
        }
        return chanceService.page(page,wrapper);
    }

    @GetMapping("/getMyChance")
    @ApiOperation(value = "获得我的抽奖次数")
    public RambleDrawChance getMyChance(){
        SysUser userInfo = LoginUtil.getUserInfo();
        return chanceService.getOne(new QueryWrapper<RambleDrawChance>().eq(RambleDrawChance.COL_PHONE,userInfo.getPhone()));
    }
}
